

<% Group.roots.sort {|a,b| a.name <=> b.name }.each do |root| %>
	<div style="margin-left:<%= root.level %>em;">
		<div id="group_id_<%= root.id %>_triangle" style="width:30px;display:inline;">
			<%= render :partial => "expand", :locals => {:group => root} %>
		</div>
		<strong><%= root.name %></strong>
		<%= link_to_remote (image_tag "settings2_16x16.gif", :size => "12x12", :border => 0, :title => 'Show Controls'), :url => {:action => 'toggle_controls', :id => root.id} %>
	</div>
	
	<div id="group_<%= root.id %>_controls" style="display:none;">
		<div id="new-child" style="margin-left:<%= root.level + 1 %>em;">
			<% form_remote_tag :url => {:action => 'new_child', :parent_id => root.id, :root_id => root.root} do %>
			Child Group Name: <%= text_field 'child_group', 'new_name' %>
			<%= submit_tag "Create" %>
			<% end %>
		</div>
	<div id="message-black" style="margin-left:<%= root.level + 1 %>em;">
		<% form_tag :action => 'make_root_child_of', :id => root.id do %>
		Make this group a child of: <%= collection_select 'new', 'parent', Group.find(:all), 'id', 'name' %>
		<%= submit_tag 'Go' %>
		<% end %>
	</div>
	</div>
	
	<div id="root_<%= root.id %>_groups">
		<%= render :partial => "group", :collection => root.children(:scope => current_user.group_scope).sort {|a,b| a.name <=> b.name} %>
	</div>
<% end %>